﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace CommonMvc.Models.Appointment
{
    /// <summary>
    /// 预约model
    /// </summary>
    public class Appointment : BasicEntityModel
    {
        public int Id { get; set; }
        //用户名
        [Required(ErrorMessage = "是必须的")]
        [MaxLength(50,ErrorMessage ="名称最长50")]
        public string PersonName { get; set; }
        //用户手机号
        [Required(ErrorMessage = "是必须的")]
        [MinLength(11, ErrorMessage = "手机号长度11位")]
        [MaxLength(11, ErrorMessage = "手机号长度11位")]
        public string Phone { get; set; }
        //用户地址
        [Required(ErrorMessage = "是必须的")]
     
        [MaxLength(50, ErrorMessage = "地址最长50")]
        public string Address { get; set; }
        //用户地址
        public decimal HouseArea { get; set; }
        /// <summary>
        /// 预算钱数
        /// </summary>
        /// 
        [Required(ErrorMessage = "预算钱数是必填的")]
        [Range(0.0,10000.0,ErrorMessage = "预算只能在0 到10000 之间")]
        public decimal BudgetMoney { get; set; }
        /// <summary>
        /// 添加日期
        /// </summary>
        public DateTime Addtime { get; set; }
        /// <summary>
        /// 状态
        /// </summary>
        /// 
        [Required(ErrorMessage = "状态是必填的")]
        [Range(0,1,ErrorMessage ="状态有两种,1 预约中,2 取消请正确填写")]
        public int State { get; set; }// 1:预约中  2：取消
        /// <summary>
        /// 确认时间
        /// </summary>
        public DateTime Confirmtime { get; set; }

        public new static void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Appointment>()
                .Property(p => p.PersonName)
                .HasMaxLength(20)
                .IsRequired(true);
            modelBuilder.Entity<Appointment>()
                .Property(p => p.Phone)
                .HasMaxLength(11)
                .IsRequired(true);
            modelBuilder.Entity<Appointment>()
                .Property(p => p.Address)
                .HasMaxLength(50)
                .IsRequired(true);
            
            modelBuilder.Entity<Appointment>()
                .Property(p => p.BudgetMoney)
                .IsRequired(true);
            modelBuilder.Entity<Appointment>()
                .Property(p => p.Addtime)
                .IsRequired(true);
            modelBuilder.Entity<Appointment>()
                .Property(p => p.State)
                .IsRequired(true);
        }
    }
}
